from die import Die
from plotly.graph_objs import Bar,Layout
from plotly import offline

die_1 = Die(6)
die_2 = Die(6)
die_3 = Die(6)

results = [die_1.roll() * die_2.roll() for number in range(1000)]

print(results)
    
# 分析结果
max_number_side = die_1.number_side * die_2.number_side 
frequencies = [results.count(num_die) for num_die in range(1, max_number_side+1)]
print(f'抛掷次数={frequencies}')

# 展示结果集
x_values = list(range(1, max_number_side+1))
data = [Bar(x=x_values, y=frequencies)]

# 展示效果
x_axis_config = {'title': '结果', 'dtick': 1}
y_axis_config = {'title': '抛掷结果频率'}

my_layout = Layout(title='抛掷结果', xaxis= x_axis_config, yaxis= y_axis_config)

# 绘制展示
offline.plot({'data': data, 'layout': my_layout}, filename='d6_d6.html')
